import React from 'react';
import moment from 'moment';
import { Table, message } from 'antd';
import Tab from '../../../../TabChange';
import './index.scss';
import Api from '../../../../../utils/api';
import CommonBorder from './../../../DispatchPage/Components/CommonBorder';

const PAGE_SIZE = 10;
class RegulatoryAgencyPage extends React.PureComponent {
  constructor(props) {
    super(props);
    this.state = {
      id: props.params.id,
      data: [],
      dataCount: 0,
      currentPage: 1,
      pageSise: PAGE_SIZE,
      tab: [
        {
          label: '巡查记录',
          route: `/system/bigdata/map/records/reculatory_agency/${props.params.id}`,
        },
      ]
    };
    this.initData = :: this.initData;
  }
  componentWillMount() {
    this.initData();
  }
  initData() {
    const { pageSise, currentPage } = this.state;
    const api = new Api({
      method: 'GET',
      path: `/depts/checks/${this.state.id}`,
      query: {
        offset: (currentPage - 1) * pageSise,
        limit: pageSise
      },
      success: (res) => {
        this.setState({
          data: res.data_list,
          dataCount: res.total_count
        });
      },
      error: (msg) => {
        message.error(msg);
      }
    });
    api.run();
  }
  generatorColumns() {
    return [
      {
        title: '时间',
        dataIndex: 'check_date',
        render: text => (
          <span>{moment(text).format('YYYY/MM/DD')}</span>
        )
      },
      {
        title: '检测对象',
        dataIndex: 'name',
        render: text => (
          <span >{text}</span >
        )
      },
      {
        title: '结果',
        dataIndex: 'result_msg',
        render: text => (
          <span >{text}</span >
        )
      },
    ];
  }
  onListPageChange(page) {
    this.setState({ currentPage: page }, () => { this.initData(); });
  }
  render() {
    const columns = this.generatorColumns();
    console.log(this.state.dataCount);
    return (
      <div className="content-wrapper">
        <div className="content-tab">
          <Tab
            configTab={this.state.tab}
          />
        </div>
        <CommonBorder
          content={
            <Table
              rowKey={record => record.id}
              columns={columns}
              bordered
              dataSource={this.state.data}
              pagination={{
                pageSize: this.state.pageSise,
                total: this.state.dataCount,
                current: this.state.currentPage,
                onChange: this.onListPageChange.bind(this)
              }}
            />
          }
        />
      </div>
    );
  }
}

export default RegulatoryAgencyPage;
